/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package tabel;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import oracle.jdbc.pool.OracleDataSource;
/**
 *
 * @author Asus
 */
public class CreateTablePunyaDosis {
public static void main(String[] args) {
        String jdbcUrl = "jdbc:oracle:thin:@localhost:1521:xe";
        String userid = "hr"; // gantikan dengan username anda
        String password = "115314023"; // gantikan dengan password anda

        Connection conn;
        try {
            OracleDataSource ds;
            ds = new OracleDataSource();
            ds.setURL(jdbcUrl);
            conn = ds.getConnection(userid, password);
            System.out.println("Koneksi is OK");
            Statement statement = conn.createStatement();
            String sql = " CREATE table PUNYADOSIS ( "
                    + "KODEOBAT VARCHAR2(10) NOT NULL "
                    + "constraint PUNYADOSIS_FK REFERENCES OBAT(KODEOBAT),"
                    + "IDDOSIS VARCHAR2(10) NOT NULL "
                    + "constraint PUNYADOSIS_FK2 REFERENCES DOSIS(IDDOSIS))";

            statement.executeUpdate(sql);

        } catch (SQLException e) {
// perform error handling here
            System.out.println("error :" + e.getMessage());
        }
    }
}
